﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Globalization;
using System.Text;

namespace ContractManagementSystem.Common
{
    public sealed class ValidateHelper
    {
        private ValidateHelper(){}

        public static bool IsValidDateTime(string dateTimeToCheck, string dateTimeFormat)
        {
            DateTime myDateTimeResult;
            return DateTime.TryParseExact(dateTimeToCheck, dateTimeFormat, CultureInfo.CurrentCulture,DateTimeStyles.None, out myDateTimeResult);
        }

        public static bool IsValidFloat(string numericToCheck)
        {
            float myFloatResult;
            return float.TryParse(numericToCheck, NumberStyles.None, CultureInfo.CurrentCulture, out myFloatResult);
        }

        public static bool IsValidDescript(string descript)
        {
            return string.IsNullOrEmpty(descript.Trim());
        }

        public static bool IsValidDataTableNotNull(DataTable dataTable)
        {
            if(dataTable.Rows.Count == 0 || dataTable.Columns.Count == 0)
            {
                return false;
            }

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                for (int j = 0; j < dataTable.Columns.Count; j++)
                {
                    if(dataTable.Rows[i].IsNull(j))
                    {
                        return false;
                    }
                }
            }
            return true;
        }

        public static int RemoveRowsNull(DataTable dataTable)
        {
            int resut = 0;
            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                for (int j = 0; j < dataTable.Columns.Count; j++)
                {
                    if (dataTable.Rows[i].IsNull(j))
                    {
                        dataTable.Rows.RemoveAt(i);
                        resut += 1;
                    }
                }
            }

            return resut;
        }
    }
}
